import axios from "axios";

//设置一些通用的配置
const instance = axios.create({

    baseURL: "http://39.99.98.192/django-shop",
    timeout: 3000,
//headers:{ 'Content-Type': 'application/x-www-form-urlencoded' } 可以不写
})


instance.interceptors.request.use(
    function (config) {
        //在请求头添加token
        config.headers["Authorization"] = localStorage.getItem("token")?"Bearer " + localStorage.getItem("token"):""
        return config
    },
    function (error){
        //confing报错才能触发
        return error

    }
)

instance.interceptors.response.use(

    function (repsonse){
        if (repsonse.status < 300){
            return repsonse
        }


    },
    function (error){
        if (error.response.status === 401){

       }
        return error
}
)



export default instance